package com.xzy.mybatis.cipher.support.strategy.crypto;

import cn.hutool.crypto.symmetric.DES;
import com.xzy.mybatis.cipher.support.enums.CryptoStrategyEnum;

import java.nio.charset.StandardCharsets;

/**
 * 对称加密：DEC
 *
 * @author xzy.xiao
 * @since 2025/1/17  14:20
 */
public class DesCryptoStrategy extends CryptoStrategy {

    private final DES des;

    public DesCryptoStrategy(String key) {
        super(key);
        this.des = new DES(key.getBytes());
    }

    @Override
    public String getName() {
        return CryptoStrategyEnum.DES.getCode();
    }

    @Override
    public String encrypt(String value) {
        return des.encryptBase64(value);
    }

    @Override
    public String decrypt(String value) {
        return des.decryptStr(value, StandardCharsets.UTF_8);
    }
}
